package com.swanclouds.redfish.account.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.swanclouds.model.account.LdapControllerResource;
import com.swanclouds.redfish.common.redfish.MemberModel;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 张立强
 * @version jdk1.8.0
 */
public class LdapControllerResourceModel implements LdapControllerResource {

    @JsonProperty("@odata.id")
    private String dataId;

    @JsonProperty("@odata.context")
    private String context;

    @JsonProperty("@odata.type")
    private String type;

    @JsonProperty("Name")
    private String name;

    @JsonProperty("Members@odata.count")
    private Integer count;

    @JsonProperty("Members")
    private List<MemberModel> controllers;
    /**
     * 集合资源的访问路径 @odata.id
     *
     * @return dataId
     */
    @Override
    public String getDataId() {
        return this.dataId;
    }

    /**
     * 集合资源模型的描述信息 @odata.context
     *
     * @return context
     */
    @Override
    public String getContext() {
        return this.context;
    }

    /**
     * 集合资源的类型 @odata.type
     *
     * @return type
     */
    @Override
    public String getType() {
        return this.type;
    }

    /**
     * 资源名称 Name
     *
     * @return name
     */
    @Override
    public String getName() {
        return this.name;
    }
    /**
     * Ldap控制器个数
     *
     * @return this Ldap Controller count
     */
    @Override
    public Integer getCount() {
        return this.count;
    }

    /**
     * Ldap控制器地址集合
     *
     * @return this Ldap Controller Collection
     */
    @Override
    public List<String> getControllers() {
        if (this.controllers == null) {
            return Lists.newArrayList();
        }
        return this.controllers.stream().map(MemberModel::getDataId).collect(Collectors.toList());
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "LdapControllerResourceModel {" +
                "dataId='" + dataId + '\'' +
                ", context='" + context + '\'' +
                ", type='" + type + '\'' +
                ", name='" + name + '\'' +
                ", count=" + count +
                ", controllers=" + controllers +
                '}';
    }
}
